﻿using System;
using System.Collections.Generic;
using System.Linq;
using Domain.Dummies;
using Domain.Dummies.Dtos;
using Domain.Dummies.Dtos.Collections;

namespace Services.Dummies.DirectorateService
{
    public class DummyDirectorateService : IDirectorateService
    {
        public Guid CreateSubject(SessionDto session, string subjectName)
        {
            var subject = new SubjectDto
                              {
                                  Id = Guid.NewGuid(),
                                  Name = subjectName
                              };
            Database.get().Subjects.Add(subject);
            return subject.Id;
        }

        public bool AttachTeacher(SessionDto session, Guid subjectId, Guid teacherId, int hours)
        {
            if (Database.get().Subjects.Count(x => x.Id == subjectId) != 1)
                return false;
            var subject = Database.get().Subjects
                .Where(x => x.Id == subjectId)
                .Single();
            //subject.TeacherId = teacherId;
            subject.Hours = hours;
            return true;
        }


        public SubjectDto GetSubject(SessionDto session, Guid SubjectGuid)
        {
            SubjectDto subjectdto = new SubjectDto()
            {
                Id = Guid.Empty,
                Name = "Такой предмет не найден"
            };

            IEnumerable<SubjectDto> query = Database.get().Subjects.Where(subject => subject.Id.Equals(SubjectGuid));
            if (query.Count() != 0)
                subjectdto = query.First();

            return subjectdto;
        }
        public SubjectBaseListDto GetSubjects(SessionDto session)
        {
            SubjectBaseListDto baselist = new SubjectBaseListDto();
            baselist.Subjects = Database.get().Subjects.ToList();
            return baselist;
        }
    }
}
